#include "StdAfx.h"
#include "SContainer.h"

SContainer::SContainer(void)
{
}

SContainer::~SContainer(void)
{
}

int SContainer::GetCount() const
{
	return (int)m_lCtrl.size();
}

void SContainer::Add(SControl * pCtrl)
{
	list<SControl *>::iterator it = m_lCtrl.begin();
	for (; it != m_lCtrl.end(); it++)
	{
		SControl * p = *it;
		if (p == pCtrl)
		{
			return ;
		}
	}

	m_lCtrl.push_back(pCtrl);
	pCtrl->Fresh();
}

SControl * SContainer::GetAt(int nItem)
{
	int nNo = 0;
	SControl * pCtrl = NULL;
	list<SControl *>::iterator it = m_lCtrl.begin();
	while(it != m_lCtrl.end())
	{
		if (nNo == nItem)
		{
			pCtrl = *it;
			break;
		}
		nNo ++;
		it ++;
	}
	return pCtrl;
}

SControl * SContainer::First()
{
	SControl * pCtrl = NULL;
	list<SControl *>::iterator it = m_lCtrl.begin();
	if (it != m_lCtrl.end())
	{
		pCtrl = *it;
	}
	return pCtrl;
}

void SContainer::Remove(SControl* pCtrl)
{
	for(list<SControl*>::iterator it = m_lCtrl.begin(); it != m_lCtrl.end(); ++it)  
	{  
		if( (*it) == pCtrl )  
		{			
			m_lCtrl.erase(it);
			if (pCtrl != NULL)
			{
				delete pCtrl;
			}
			return ;
		}
	}
}

char * SContainer::GetType()
{
	return "SContainer";
}

bool SContainer::IsType(char * pCtrlType)
{
	if (!strcmp(pCtrlType, "SContainer"))
		return true;

	return false;
}
